package cz.cvut.fit.crhonjar.mi.run.hawera.tree.statement;

import cz.cvut.fit.crhonjar.mi.run.hawera.tree.Tree;
import cz.cvut.fit.crhonjar.mi.run.hawera.tree.TreeVisitor;
import cz.cvut.fit.crhonjar.mi.run.hawera.tree.expression.ExpressionTree;
import cz.cvut.fit.crhonjar.mi.run.hawera.tree.expression.FunctionCallTree;

/**
 * tree representing assignment
 * 
 * @author Jarec
 * 
 */
public class AssignmentTree extends Tree {

	private FunctionCallTree identifier;
	private ExpressionTree expression;
	private ExpressionTree condition;

	/**
	 * constructor of AssignmentTree
	 * 
	 * @param identifier
	 * @param expression
	 * @param condition
	 */
	public AssignmentTree(FunctionCallTree identifier,
			ExpressionTree expression, ExpressionTree condition) {
		super();
		this.log.debug("> AssigmentTree");
		if (identifier == null) {
			this.log.error("identifier is null!");
			throw new NullPointerException(
					"identifier in AssigmentTree constructor");
		}
		if (expression == null) {
			this.log.error("expression is null");
			throw new NullPointerException(
					"expression in AssigmentTree constructor");
		}
		this.condition = condition;
		this.identifier = identifier;
		this.expression = expression;
		this.log.debug("< AssignmentTree");
	}

	@Override
	public void accept(TreeVisitor visitor) {
		visitor.visitAssignment(this);

	}

	/**
	 * @return the condition
	 */
	public ExpressionTree getCondition() {
		this.log.debug(">< getCondotion exist?: {}", this.condition != null);
		return this.condition;
	}

	/**
	 * gets assigned expression
	 * 
	 * @return
	 */
	public ExpressionTree getExpression() {
		this.log.debug(">< getExpression (right side)");
		return this.expression;
	}

	/**
	 * gets identifier
	 * 
	 * @return
	 */
	public FunctionCallTree getIdentifier() {
		if (this.log.isDebugEnabled()) {
			this.log.debug(">< getIdentifier name: {} isFunction: {}",
					this.identifier.getName(), this.identifier.isFunction());
		}
		return this.identifier;
	}

}
